<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/20 00:00
 */

namespace module\chat\front\form;

use module\chat\enum\RoleEnum;
use mof\enum\StatusEnum;
use mof\front\Form;
use mof\Model;

class CategoryForm extends Form
{
    protected array $validate = [
        'param' => [
            'type', 'name', 'icon', 'listorder/d', 'status/d', 'remark'
        ],
        'rule'  => [
            'type|分类类型' => 'require|in:assistant,visrole',
            'name|分类名称' => 'require|length:2,30',
            //'icon|图标'     => 'require|storage',
            'status|状态'   => 'require|in:0,1',
            'remark|备注'   => 'length:0,200',
        ],
    ];

    protected function elements(Model $model = null): array
    {
        return [
            [
                "label"   => "分类类型",
                "prop"    => "type",
                "value"   => $model['type'] ?? '',
                "type"    => "select",
                "options" => RoleEnum::toDict()->toElementData()->toSelectOptions(),
            ],
            [
                "label" => "分类名称",
                "prop"  => "name",
                "value" => $model['name'] ?? '',
            ],
            [
                "label" => "图标",
                "prop"  => "icon",
                "value" => $model['icon'] ?? '',
                "type"  => "upload:image"
            ],
            [
                "label" => "排序",
                "prop"  => "listorder",
                "value" => $model['listorder'] ?? 0
            ],
            [
                "label"   => "状态",
                "prop"    => "status",
                "value"   => $model['status'] ?? 1,
                "type"    => "select",
                "options" => StatusEnum::toDict()->toElementData()->toSelectOptions(),
            ],
            [
                "label" => "备注",
                "prop"  => "remark",
                "value" => $model['remark'] ?? ''
            ],
        ];
    }
}